<?php
namespace Crm\Table;

use Zend\Db\Sql\Select;
use Zend\Db\Sql\Where;
class FeedbackTable extends AbstractTable
{
    protected $table = 'hy_feedback';
    protected $id = 'id';
    
    
    public function getFeedbackList($query = array())
    {
        $select = new Select(array('f' =>$this->getTable()));
        
        $select->join(
            array('u' => 'hy_user'),
            'f.user_id = u.user_id',
            array('user_name') ,
            $select::JOIN_LEFT
        );
        
        $where = new Where();
        if(!empty($query['user_name'])) {
            $where->like('u.user_name', '%'.$query['user_name'].'%');
        }
        if(!empty($query['user_id'])) {
            $where->equalTo('f.user_id', $query['user_id']);
        }
        if(!empty($query['start_time'])) {
            $where->greaterThan('f.create_time', $query['start_time']);
        }
        if(!empty($query['end_time'])) {
            $where->lessThan('f.create_time', $query['end_time']);
        }

        $select->where($where);
        
        $select->order('f.id desc');
        return $this->fetchPaginate($select,$query);
    }

    public function getOutExcelList()
    {
        $select = new Select(array('f' =>$this->getTable()));
        $select->join(
            array('u' => 'hy_user'),
            'f.user_id = u.user_id',
            array('user_name') ,
            $select::JOIN_LEFT
         );
        $select->order('f.id');
         
        $rowset = $this->selectWith($select);
        $list = $rowset->toArray();
    
        return $list;
    }
}